package top.ashman.demo.springcloud.hystrix;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import org.springframework.stereotype.Service;

/**
 * @author sunzhaojie
 * @date 2018-12-12
 */
@Service
public class MyService {

    @CacheResult
    @HystrixCommand
    String hello(String name) {
        System.out.println("Hello from " + name);
        return "Hello " + name;
    }

    @CacheResult(cacheKeyMethod = "getHelloCacheKey")
    @HystrixCommand
    String hello() {
        System.out.println("Hello World");
        return "Hello World";
    }

    private String getHelloCacheKey() {
        return "default";
    }

    @CacheResult
    @HystrixCommand
    String hello(String name1, String name2) {
        System.out.println("Hello from " + name1 + " and " + name2);
        return "Hello " + name1 + " and " + name2;
    }
}
